<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String action = (String)request.getParameter("key");
if(action == null || action.trim().equals("") || action.trim().equals("undefined")){
	out.println("<script>alert('无操作类型!');window.close();</script>");
}
String title = "";
if(action.equals("in")) title = "客户信息导入";
else if(action.equals("out")) title = "客户信息导出";

String customerId = (String)request.getParameter("cid");
if(customerId == null) customerId = "";
String type = (String)request.getParameter("type");
if(type == null) type = "";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>数据同步-<%=title%></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<jsp:include page="../public/publicJs.jsp" flush="false"></jsp:include>
<script language="javascript">
function exportIn(){
  	if(document.getElementById("fileControl").value == ""){
  		document.getElementById("msg").innerHTML = "<font color=red>未选择文件!</font>";
  		return false;
  	}
    document.forms[0].encoding = "multipart/form-data";
	document.forms[0].action = "<%=basePath%>export.crm?method=in";
	document.getElementById("msg").innerHTML = "<font color='#FF0000'><img src='<%=basePath%>images/loading.gif' alt='文件导入中' align='absmiddle' class='icon1'/> 文件导入中,请稍后......</font>";
	document.forms[0].submit();
	return true;
}
function exportOut(){
	document.forms[0].action = "<%=basePath%>export.crm?method=out";
	document.forms[0].encoding="application/x-www-form-urlencoded";
	document.getElementById("msg").innerHTML = "<font color='#FF0000'><img src='<%=basePath%>images/loading.gif' alt='文件导出中' align='absmiddle' class='icon1'/> 文件导出中,请稍后......</font>";
	document.forms[0].submit();
	return true;
}
function callback(msg){
	if(msg != ""){
		var index = msg.indexOf("{[success]");
		if(index>-1){
			var fileName = msg.substring(index, msg.length-1);
			msg = msg.substring(0, index);
			document.getElementById("msg").innerHTML = "<font color='red'>"+msg+"</font>";
			fileName = fileName.replace("{[success]", "");
			downLoad(fileName);
		}
		else
	  		document.getElementById("msg").innerHTML = "<font color='red'>"+msg+"</font>";
	}
	document.forms[0].action = "";
	document.forms[0].encoding="application/x-www-form-urlencoded";
}
function downLoad(fileName){
	var url = "<%=basePath%>upload/export_out/"+fileName;
	var obj = window.open(url, "", fnGetWinStatus(100,100));
	obj.document.execCommand('Saveas', true, fileName);
	obj.close();
}
</script>
</head>
<body text="#000000" bgcolor="#FFFFFF" TOPMARGIN="0" LEFTMARGIN="0"	style="overflow-y:hidden;border:1px solid #8DB2E3;">
<form action="" method="post" name="form1" target="hidden_frame">
<table class="title_top" width=100% align=center border="0" cellspacing="0" cellpadding="0">
	<tr valign="top" class="tree_title_txt">
		<td class="tree_title_txt" width=100% height=26 align=center valign="middle">数据同步-<%=title%></td>
	</tr>
	<tr valign="top">
	<td>
<div class="tabBody" style="margin:12px;padding:12px;height:240px">
<%
	if(action.equals("in")){
%>
   <table width="98%" border="0" align="center">
     <tr>
       <td valign="top" width="26%">导入的EXCEL文件：</td>
       <td width="77%"><input id="fileControl" name="fileControl" type="file" class="text" style="width:320px"></td>
     </tr>
	 <tr>
	   <td colspan="2" align="left"><span id="msg" style="text-align:left; width:100%"></span></td>
	 </tr>
  </table>
<%
	}else if(action.equals("out")){
%>
	<table cellSpacing="0" cellPadding="0" id="table13"  width="90%" border="0" align="center">
	<tr>
		<td width="15%"><nobr>文件名：</nobr></td>
		<td width="85%"><input type="text" name="fileName" class="text" style="width:350px" /></td>
	</tr>
	<tr>
	 	<td colspan="2" align="left">
	 		<input type="hidden" name="cid" value="<%=customerId%>"/>
	 		<input type="hidden" name="type" value="<%=type%>"/>
	 		<span id="msg" style="text-align:left; width:100%"></span>
	 	</td>
	</tr>
	</table>
<%
	}
%>
  <iframe name='hidden_frame' id="hidden_frame" style='display:none'></iframe>
</div>
<div style="margin:12px" align="right">
<table border="0" cellspacing="0" cellpadding="0">
<tr valign="top">
	<td id="btnCancel" valign="middle" align="right" width="50%">
<%
	if(action.equals("in")){
%>
		<input name="bup" type="button" value="开始导入" class="btn3_mouseout" onClick="exportIn()" style="margin-right:0px">
<%
	}else if(action.equals("out")){
%>
		<input name="buo" type="button" value="开始导出" class="btn3_mouseout" onClick="exportOut()" style="margin-right:0px">
<%
	}
%>
	</td>
	<td id="btnCancel" valign="middle" align="left" width="50%">
		&nbsp;&nbsp;<button onClick="window.close()" class="btn3_mouseout">关闭</button>
	</td>
</tr>
</table>
</div>
</td></tr>
</table>
</form>
</body>
</html>